<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="redis" uri="http://www.shopjsp.com/redisTag/functions" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="basePath" value="${redis:getSysConfig('base_path_back')}"/>
<script type="text/javascript">
    /**
     * 自定义验证规则
     */
    function validateForm(){
        form.bootstrapValidator({
            message: "无效的值",
            feedbackIcons: {
                valid: "glyphicon glyphicon-ok",
                invalid: "glyphicon glyphicon-remove",
                validating: "glyphicon glyphicon-refresh"
            },
            fields: {
                categoryName: {
                    validators: {
                        notEmpty: {message: "分类名称不可为空"},
                        stringLength: {min: 2,max: 20,message: "分类名称长度为2至20"}
                    }
                },
                sortCode: {
                    validators: {
                        notEmpty: {message: "排序号不可为空"},
                        stringLength: {max: 4,message: "排序号最大长度为4"},
                        numeric: {
                            message: '排序号只能输入数字'
                        }
                    }
                },
                keywords: {
                    validators: {
                        stringLength: {max: 50,message: "seo关键字最大长度为50"},
                        regexp: {
                            regexp: validateUtil.chinese,
                            message: '只能输入中文'
                        }
                    }
                }
            }
        });
    }

    /**
     * 添加分类名称
     */
	<shiro:hasPermission name="back_gotoCategoryList_add">
    function addInfo(){
        $("#myModalLabel").empty().text("添加分类信息");
        /**清空隐藏域的值**/
        $("#categoryId").val("");
        $("#isLeaf").val("");
        $("#levelCode").val("");
        /**设置固定隐藏域的值  通过左侧的树节点点击展示右侧的子节点列表，则节点的id为列表的子节点的父id**/
        $("#parentId").val($("#q_categoryId").val());
        resetAddForm();
    }
	</shiro:hasPermission>

    /**
     * 编辑分类名称
     */
	<shiro:hasPermission name="back_gotoCategoryList_update">
    function editInfo(){
        $("#myModalLabel").empty().text("修改分类信息");
        /**获取选中行的id**/
        var selectedRow= $("#tt").bootstrapTable('getSelections');
        if(selectedRow.length==1){
            var id=selectedRow[0].categoryId;
            $("#btn_edit").attr("data-target","#addOrEditModal");/**选中了记录后才可打开对应的模态框**/
            $.ajax({
                type: "POST",
                dataType: "JSON",
                url: "${basePath}/back/category/loadCmsCategory.sjson",
                data: {categoryId:id},
                success: function(result){
                    var data = JSON.parse(result.data);
                    /**隐藏域**/
                    $("#categoryId").val(data.categoryId);
                    $("#parentId").val(data.parentId);
                    $("#isLeaf").val(data.isLeaf);
                    $("#levelCode").val(data.levelCode);
                    /**可见表单控件**/
                    $("#categoryName").val(data.categoryName);
                    $("#keywords").val(data.keywords);
                    $("#sortCode").val(data.sortCode);
                }
            });
        }else{
            $("#btn_edit").attr("data-target","");/**没有选中记录不可打开模态框**/
            showMsg("请选择一行记录！");
        }
    }
    </shiro:hasPermission>

</script>

<!--添加编辑模态框（Modal） -->
<div class="modal fade" id="addOrEditModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static">
	<div class="modal-dialog" style="width:70%">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				<h5 class="modal-title" id="myModalLabel"></h5>
			</div>
			<div class="modal-body">
				<form id="form1"  method="post" action="${basePath}/back/category/saveOrUpdateCategory.sjson">
					<input id="categoryId" type="hidden" name="categoryId"/>
					<input id="isLeaf" type="hidden" name="isLeaf" />
					<input id="levelCode" type="hidden" name="levelCode" />
					<input id="parentId" type="hidden" name="parentId" value=""/>
					<table align="center" class="addOrEditTable table-bordered table" style="width:100%;">
						<tr>
							<td class="toright_td" width="150px"><span style="color:red">* </span>分类名称:&nbsp;&nbsp;</td>
							<td  class="toleft_td">
								<div class="form-group">
									<input id="categoryName" class="form-control input-sm" type="text" name="categoryName" placeholder="请输入分类名称"/>
								</div>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px"><span style="color:red">* </span>排序:&nbsp;&nbsp;</td>
							<td  class="toleft_td">
								<div class="form-group">
									<input id="sortCode" class="form-control input-sm" type="text" name="sortCode" placeholder="请输入排序"/>
								</div>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px"><span style="color:red">* </span>关键词:&nbsp;&nbsp;</td>
							<td  class="toleft_td">
								<div class="form-group">
									<input id="keywords" class="form-control input-sm" type="text" name="keywords" placeholder="请输入关键词"/>
								</div>
							</td>
						</tr>
					</table>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" id="validateBtn" class="btn btn-primary"  onclick="submitForm()">保存</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
			</div>

		</div><!-- /.modal-content -->
	</div><!-- /.modal -->
</div>
